package com.zsj.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @author zsj
 * @version 1.0
 * @date 2024/4/22 15:47
 * @description
 */
public class Demo {
    public static void main(String[] args) {
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.MILLISECONDS.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "ok";
        });

        try {
            future.get(1, TimeUnit.SECONDS);
        } catch (Exception e) {
            System.out.println("超时了我操你妈");
            e.printStackTrace();
        }
    }
}
